package com.yufc.mvcdemo.controller;

import com.yufc.mvcdemo.domain.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: yufc
 * @Date: 2018-10-28 11:23
 * @Description:
 */
@Controller
@RequestMapping("/hello")
public class HelloMvcController {

    @RequestMapping("/mvc")
    public String HelloWorld(){
        return "home";
    }


    @RequestMapping(value = "users", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public ResponseEntity<List<User>> getUsers(){
        List<User> userList = new ArrayList<>();
        User u = new User();
        u.setId(1);
        u.setName("中国");
        userList.add(u);

        u = new User();
        u.setId(2);
        u.setName("美国");
        userList.add(u);

        u = new User();
        u.setId(3);
        u.setName("英国");
        userList.add(u);

        return new ResponseEntity<>(userList, HttpStatus.OK);
    }

    @RequestMapping(value = "users2", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public List<User> getUsers2(){
        List<User> userList = new ArrayList<>();
        User u = new User();
        u.setId(1);
        u.setName("泵车");
        userList.add(u);

        //aaa
        u = new User();
        u.setId(2);
        u.setName("bbb");
        userList.add(u);

        u = new User();
        u.setId(3);
        u.setName("ccc");
        userList.add(u);

        return userList;
    }
}
